﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace console.demo.senior
{
    public class ThreadDemo
    {

        public ThreadDemo() { }
        public void TestThread()
        {
            Thread th = Thread.CurrentThread;
            th.Name = "MainThread";
            Console.WriteLine("this is {0}", th.Name);
            Console.ReadKey();
        }

        public static void CallToChildThread()
        {
            Console.WriteLine("child thread starts");
            int sleepFor = 5000;
            Console.WriteLine("child thread paused for {0} seconds", sleepFor / 1000);
            Thread.Sleep(sleepFor); ;
            Console.WriteLine("child thread resumes");
        }

        public static void callToChildThread()
        {
            try
            {
                Console.WriteLine("child thread starts");
                for (int i = 0; i <= 10; i++)
                {
                    Thread.Sleep(500);
                    Console.WriteLine(i.ToString());
                }
                Console.WriteLine("child thread completed");
            }
            catch (Exception)
            {
                Console.WriteLine("thread abort exception");
            }
            finally
            {
                Console.WriteLine("couldnt catch the thread exception");
            }
        }
    }
}
